<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of Moyoyo
 *
 * @author dragon.hu add @2016.3.16
 */
require_once 'BaseChannel.php';

//魔游游
class Moyoyo implements BaseChannel 
{
	
	function __construct() 
	{
		//echo "construct";
	}

	//put your code here
	function android($data) 
	{
		$paymentKey="rq6mj278rf5cd8un"; //通知码
		$ret = $this->paymentCallBack($paymentKey, ANDROID);
		echo $ret;
	}

	function ios($data) 
	{
		$paymentKey=""; //秘钥
		$ret = $this->paymentCallBack($paymentKey, IOS);
		echo $ret;
	}

	function paymentCallBack($paymentKey, $platform)
	{
		$orderLog = new ChargeOrder();
		$orderLog->log("moyoyo", $_REQUEST);
		
		$serverid = $_REQUEST['serverid'];
		$custominfo = $_REQUEST['custominfo'];
		$openid = $_REQUEST['openid'];
		$ordernum = $_REQUEST['ordernum'];
		$status = $_REQUEST['status'];
		$paytype = $_REQUEST['paytype'];
		$amount = $_REQUEST['amount'];
		$errdesc = $_REQUEST['errdesc'];
		$paytime = $_REQUEST['paytime'];
		$sign = $_REQUEST['sign'];
		
		$mysign = $serverid.'|'.$custominfo.'|'.$openid.'|'.$ordernum.'|'.$status.'|'.$paytype.'|'.$amount.'|'.
				$errdesc.'|'.$paytime.'|'.$paymentKey;
		
		if($sign == strtoupper(md5($mysign)))  
		{ //验证通过
			 $tmpstatus = STATUS_SUCCESS;
			 if ($status != 1)
			 {
			 	$tmpstatus = STATUS_FAILD;
			 }
			//进行发货
			if(false == $orderLog->recordOrder($tmpstatus, $amount/100, $custominfo, "moyoyo", $platform,$ordernum))
			{
				$ret="0";
				$orderLog->log("moyoyo",array("order"=>$custominfo,"money"=>$amount,"serverresult"=>"faild"));
			}else 
			{
				//支付成功
				$ret="1";
				$orderLog->log("moyoyo",array("order"=>$custominfo,"money"=>$amount,"serverresult"=>"success"));
			}
			 
		} else {
			//"$sig验证失败"
			$ret="0";
			$orderLog->log("moyoyo","  order:$custominfo sign error sign:$sign mysign:$mysign");
		}
		return $ret;
	}
	
}